﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.Skins;
using DevExpress.LookAndFeel;
using DevExpress.UserSkins;
using DevExpress.XtraBars;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraBars.Helpers;
namespace NotebookS2.Inventory.Dialogs
{
    public partial class FND_REVALITEM : RibbonForm
    {
        public FND_REVALITEM()
        {
            InitializeComponent();
        }

        public string ConnectionString { get; set; }

        public string SelectedItemCode { get; set; }
        public string SelectedItemName { get; set; }
        public string SelectedUnitCost { get; set; }

        private void FND_REVALITEM_Load(object sender, EventArgs e)
        {
            cboSearch.SelectedIndex = 0;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void txtSearch_EditValueChanged(object sender, EventArgs e)
        {

        }

        private void txtSearch_BindingContextChanged(object sender, EventArgs e)
        {

        }

        private void txtSearch_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            string _QUERY_ITEMCODE = "SELECT DISTINCT ItemCode, ItemName, UoM, UnitCost FROM STOCKCARD WHERE ItemCode LIKE @SearchVal";
            string _QUERY_ITEMNAME = "SELECT DISTINCT ItemCode, ItemName, UoM, UnitCost FROM STOCKCARD WHERE ItemName LIKE @SearchVal";

            SqlConnection oConnection = new SqlConnection();
            SqlCommand oCommand = new SqlCommand();

            oConnection.ConnectionString = this.ConnectionString;
            oCommand.Connection = oConnection;
            if(cboSearch.SelectedIndex == 0){
                oCommand.CommandText = _QUERY_ITEMCODE;
            }else{
                oCommand.CommandText = _QUERY_ITEMNAME;
            }

            string searchvalue = "%" + txtSearch.Text + "%";
            oCommand.Parameters.Add(new SqlParameter("@SearchVal", searchvalue));

            SqlDataAdapter oAdapter = new SqlDataAdapter();
            DataSet ds = new DataSet();

            oAdapter.SelectCommand = oCommand;
            oAdapter.Fill(ds);

            gridControl1.DataSource = ds.Tables[0];
            gridControl1.Refresh();

        }

        private void btnChoose_Click(object sender, EventArgs e)
        {
            this.SelectedItemCode = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, gridView1.Columns["ItemCode"]).ToString();
            this.SelectedItemName = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, gridView1.Columns["ItemName"]).ToString();
            this.SelectedUnitCost = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, gridView1.Columns["UnitCost"]).ToString();

            this.Close();
        }
    }
}
